import React from 'react';
import ReactDOM from 'react-dom/client';
import FilterableProductTable from './App';
// const pops = [
//     {category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football",id:1},
//     {category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball",id:1},
//     {category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball",id:2},
//     {category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch",id:2},
//     {category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5",id:3},
//     {category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7",id:4}
//   ];


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(

<FilterableProductTable/>
);

// 订阅发布模型
class DataSource {

  constructor(){
    // 订阅者
    this.listener = []

  }
// 订阅报纸
  addChange(demo){
    this.listener.push(demo)
    // console.log(this.listener.length)
  }
// 取消订阅
  removechange(demo){
    var index = this.listener.indexOf(demo)
    this.listener.splice(index,1)
  }
// 发布报纸
  publish(data){

    for(let i =0;i<this.listener.length;i++)
    {
      const listener =this.listener[i]
      listener(data)
    }
  }

}

const Dactage = new DataSource()
Dactage.addChange((data) => {
  console.log('真开心收到了报纸',data)
  // console.log('123',this.listener)
})
Dactage.addChange((data) => {
  console.log('真开心收到了报纸',data)
  // console.log('123',this.listener)
})
// Dactage.addChange((data) => {
//   console.log('真开心收到了报纸',data)
//   // console.log('123',this.listener)
// })
Dactage.publish('cf火麒麟')


